package io.renren.controller;

import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.entity.SbydglEntity;
import io.renren.service.SbydglService;
import io.renren.utils.PageUtils;
import io.renren.utils.Query;
import io.renren.utils.R;

import javax.servlet.http.HttpServletRequest;


/**
 * 商保异动管理
 * 
 * @author zhangheng
 * @email zh_123shmily@163.com
 * @date 2017-08-03 15:03:42
 */
@RestController
@RequestMapping("sbydgl")
public class SbydglController extends AbstractController{
	@Autowired
	private SbydglService sbydglService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("sbydgl:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<SbydglEntity> sbydglList = sbydglService.queryList(query);
		int total = sbydglService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(sbydglList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{ydId}")
	@RequiresPermissions("sbydgl:info")
	public R info(@PathVariable("ydId") Integer ydId){
		SbydglEntity sbydgl = sbydglService.queryObject(ydId);
		
		return R.ok().put("sbydgl", sbydgl);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("sbydgl:save")
	public R save(@RequestBody SbydglEntity sbydgl){
		sbydglService.save(sbydgl);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("sbydgl:update")
	public R update(@RequestBody SbydglEntity sbydgl){
		sbydglService.update(sbydgl);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("sbydgl:delete")
	public R delete(@RequestBody Integer[] ydIds){
		sbydglService.deleteBatch(ydIds);
		
		return R.ok();
	}
	/**
	 * 生成表单和明细
	 */
	@RequestMapping("/addSbyd")
	public R addSbyd(@RequestBody JSONObject params){
		sbydglService.addSbyd(params,getUser());
		return R.ok();
	}
	/**
	 * 生成表单和明细
	 */
	@RequestMapping("/getbatchcode")
	public R getBatchCode(){
		return R.ok().put("batchcodelist",sbydglService.getBatchCode());
	}
	/**
	 * 新增商报付款
	 */
	@RequestMapping("/addBusinesspay")
	public R addBusinesspay(@RequestBody Integer[] ydDetIds,HttpServletRequest request){
		sbydglService.addBusinesspay(ydDetIds,request,getUser());
		return R.ok();
	}
}
